package com.asm.DBloader;

import java.util.ArrayList;

import android.R.string;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class ASM_fCompanySettingDS {
	private SQLiteDatabase dB;
	private ASM_DB dbHelper;
	Context context;

	
	public ASM_fCompanySettingDS (Context context)
	{
		this.context = context;
		dbHelper = new ASM_DB(context);
	}
	
	public void open() throws SQLException
	{
		dB = dbHelper.getWritableDatabase();
	}
	
	@SuppressWarnings("static-access")
	public int Create(ASM_fCompanySetting det) {
		
		int count =0;
		
		if(dB == null){
			open();
		}else if(!dB.isOpen()){
			open();
		}
		
		 
	
		ContentValues values = new ContentValues();
		values.put(ASM_DB.asmfCompanySetting_cSettingsCode, det.getAsmfCompanySetting_cSettingsCode());
		values.put(ASM_DB.asmfCompanySetting_cSettingGrp, det.getAsmfCompanySetting_cSettingGrp());
		values.put(ASM_DB.asmfCompanySetting_cLocationChar, det.getAsmfCompanySetting_cLocationChar());
		values.put(ASM_DB.asmfCompanySetting_cCharVal, det.getAsmfCompanySetting_cCharVal());
		values.put(ASM_DB.asmfCompanySetting_nNumVal, det.getAsmfCompanySetting_nNumVal());
		values.put(ASM_DB.asmfCompanySetting_cRemarks, det.getAsmfCompanySetting_cRemarks());
		values.put(ASM_DB.asmfCompanySetting_nType, det.getAsmfCompanySetting_nType());
		values.put(ASM_DB.asmfCompanySetting_bUpdateFlag, det.getAsmfCompanySetting_bUpdateFlag());
		values.put(ASM_DB.asmfCompanySetting_cCompanyCode, det.getAsmfCompanySetting_cCompanyCode());
		values.put(ASM_DB.asmfCompanySetting_recordid, det.getAsmfCompanySetting_recordid());
		
		count = (int) dB.insert(ASM_DB.ASM_FCOMPANYSETTING, null, values);

		dB.close();
		return count;
		
	}
	
	
	public String getFcompanyDetails(String cSettingsCode,String ASMPreFixr) 
	{
		if (dB == null) 
		{
			open();
		} else if (!dB.isOpen()) {
			open();
		}
		String val = null;
		String val1 = null;
		String finalval = null;
		String selectQuery = "select cCharVal from fCompanySetting where cSettingsCode = '"+cSettingsCode+"'";
		
		Cursor cursor = null;
		cursor = dB.rawQuery(selectQuery, null);
		
		while(cursor.moveToNext())
		{
		
		val=cursor.getString(0);
			
		}
		String selectQuery1 = "select ASMPreFix from fASM where ASMCode = '"+ASMPreFixr+"'";
		
		Cursor cursor1 = null;
		cursor1 = dB.rawQuery(selectQuery1, null);
		
		while(cursor1.moveToNext())
		{
		
		val1=cursor1.getString(0);
			
		}
		
		finalval = val + val1;
		
	
		return finalval;
	
	}

	
	
	
}
